package com.newopenlab.hmc.util.stats;

import java.util.List;

import com.newopenlab.hmc.biz.Action;
import com.newopenlab.hmc.util.BaseHand;
import com.newopenlab.hmc.util.IPHSManager;
import com.newopenlab.hmc.util.Way;
import com.newopenlab.hmc.util.WayAction;

public class FCBetManager implements IPHSManager{
	@Override
	public BaseHand calculateStats(String playerName, BaseHand hand) {
		BaseHand bh=hand;
		List<WayAction> actions=null;
		bh=StatsUtil.initStat(playerName,bh);
		
		Boolean cbetPot=StatsUtil.lastAction(playerName, bh, Action.RAISE.toString(), Way.PREFLOP.toString());
		actions=StatsUtil.filterBetsGTZ(null,bh,new  String[] {Action.BET.toString()},new  String[] {Way.FLOP.toString()});
		if(actions.size()==0){
			if(StatsUtil.filterBetsGTZ(null,bh,new  String[] {Action.CHECK.toString()},new  String[] {Way.FLOP.toString()}).size()>0){
				cbetPot=true;
			}else{
				cbetPot=false;
			}
			
		}else if(actions.size()>0 && !actions.get(0).player.name.equals(playerName)){
			WayAction a=actions.get(0);
			actions=StatsUtil.filterBetsGTZ(playerName,bh,new  String[] {Action.CHECK.toString(),Action.CALL.toString(),Action.RAISE.toString(),Action.FOLD.toString()},new  String[] {Way.FLOP.toString()});
			if(actions.size()>0){
				cbetPot=!(StatsUtil.after(actions.get(0),a,bh));
			}
		}
		
		
		if(cbetPot){
			bh.stats.get(playerName).fCbetCounter=1;
			if(StatsUtil.lastAction(playerName, bh, Action.BET.toString(), Way.FLOP.toString())){
				bh.stats.get(playerName).fcbet=true;
			}
		}
		
		return bh;
	}
}
